#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int maxEnvelopes(vector<vector<int>>& envelopes)
{
	sort(envelopes.begin(), envelopes.end());
	int templen[envelopes.size()];
	for (int i = 0; i < envelopes.size(); ++i) {
		templen[i] = 1;
	}
	int res = 1;
	for (int i = 1; i < envelopes.size(); ++i) {
		int tempmax = 1;
		for (int j = 0; j < i; ++j) {
			if ((envelopes[j][0] < envelopes[i][0]) && (envelopes[j][1] < envelopes[i][1])) {
				if (templen[j] + 1 > tempmax) {
					tempmax = templen[j] + 1;
				}
			}
		}
		templen[i] = tempmax;
		if (templen[i] > res) {
			res = templen[i];
		}
	}
	return res;
}

int main()
{
	vector<vector<int>> a = { { 5, 4 }, { 6, 4 }, { 6, 7 }, { 2, 3 } };
	cout << maxEnvelopes(a) << endl;
}
